'''
词关系测试
'''

import gensim.downloader as api
import torch
from gensim.models import keyedvectors
from torch.nn.functional import cosine_similarity
#1.通过加载词向量模型，得到词向量对象
# wv = api.load("word2vec-google-news-300")

wv = keyedvectors.load_word2vec_format(r"/root/project/word_vector/data/GoogleNews-vectors-negative300.bin.gz",binary=True)

king_vector = torch.tensor(wv["king"]).unsqueeze(0)
queue_vector = torch.tensor(wv["queen"]).unsqueeze(0)

cos_sim = cosine_similarity(king_vector,queue_vector)
print(cos_sim)